﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using WF_DataAccess;
using System.Data;
using WF_Business;

namespace ExtBusiness.Common
{
    /// <summary>
    /// 文章管理
    /// </summary>
    public class ArticleManage
    {
        IDataAccess idaGloab = SysParams.OAConnection();

        /// <summary>
        /// 删除文章
        /// </summary>
        /// <param name="id"></param>       
        public void DeleteArticle(string id)
        {
            IDataAccess idaTemp = SysParams.OAConnection(true);          
            try
            {
                string strSql = string.Format("delete  st_other t where t.id='{0}'", id);
                idaTemp.RunSql(strSql);
                strSql = string.Format("delete ST_NOTIFYUSER t where t.sid ='{0}'", id);
                idaTemp.RunSql(strSql);
                idaTemp.Close(true);
            }
            catch
            {
                idaTemp.Close(false);
            }
        }

        /// <summary>
        /// 删除上传文件
        /// </summary>
        /// <param name="id"></param>       
        public void DeleteFiles(string id)
        {
            string strSql = string.Format("delete  xt_uploadfile t where t.id='{0}'", id);
            idaGloab.RunSql(strSql);
        }

        /// <summary>
        /// 获取大类
        /// </summary>
        /// <returns></returns>
        public DataTable GetBigType()
        {
            string sql = "select distinct type from st_other";
            DataTable dt = null;
            SysParams.OAConnection().RunSql(sql, out dt);
            return dt;
        }

        /// <summary>
        /// 获取所有的信息
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataTable GetAllAiticle(string strWhere)
        {
            string strSql = string.Format(@"select distinct t.id,t.title,t.time,t.type,t.userid,u.user_name from st_other t,st_user u where u.userid(+)=t.userid {0} order by t.time desc ", strWhere);

            DataTable dtSource;
            SysParams.OAConnection().RunSql(strSql, out dtSource);
            return dtSource;
        }
    }
}
